from telnetlib import DO

import numpy as np
from manim import *
from numpy import flip, insert
import math

LV, QL, QH, JH = '#75cfb8', '#bbdfc8', '#f0e5d8', '#ffc478'


class p1(ThreeDScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        self.set_camera_orientation(phi=75 * DEGREES, theta=-90 * DEGREES)
        # 正四面体
        tr=Triangle()
        h1=np.sqrt(1.5**2-0.5**2)
        a,b,c,d=tr.get_boundary_point(UP),tr.get_boundary_point(LEFT),tr.get_boundary_point(RIGHT),[0,0,h1]
        vg1=VGroup(tr,Line(a,d),Line(b,d),Line(c,d)).shift(LEFT).set_color(LV)
        self.add(vg1)
        # 正四棱锥
        sq=Square(np.sqrt(3))
        h2=np.sqrt(9/4-3/4)
        e,f,g,h,i=sq.get_boundary_point(UL),sq.get_boundary_point(UR),sq.get_boundary_point(DR),sq.get_boundary_point(DL),[0,0,h2]
        vg2=VGroup(sq,Line(e,i),Line(f,i),Line(g,i),Line(h,i)).shift(RIGHT).set_color(JH)
        self.add(vg2,
                 MathTex('A').rotate(75 * DEGREES,[1,0,0])
                 )

class p1(ThreeDScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        # self.set_camera_orientation(phi=75 * DEGREES, theta=-90 * DEGREES)
        # 1
        a,b=[-2.6,0,0],[-0.5,0,0]
        c,d=b+DL,a+DL
        s=a+UP*1.3+RIGHT*0.5
        vg1=VGroup(
            Line(s,d),Line(s,c),Line(s,b),
            Line(b,c),Line(c,d),
            DashedLine(s,a),
            DashedLine(a,b),DashedLine(a,d)
        ).set_color(LV)
        self.add(vg1,
                 MathTex('A').next_to(a,DOWN),
                 MathTex('B').next_to(b),
                 MathTex('C').next_to(c,DOWN),
                 MathTex('D').next_to(d,DOWN),
                 MathTex('S').next_to(s,UP)
                 )
        # 2
        a_,b_,c_,s_=[3.6,-0.5,0],[2,0,0],[1,-1,0],[2.2,1.5,0]
        vg2=VGroup(
            DashedLine(a_,b_),DashedLine(b_,c_),Line(a_,c_),
            Line(s_,a_),DashedLine(s_,b_),Line(s_,c_)
        ).set_color(JH)
        self.add(vg2,
                 MathTex(r'A^\prime').next_to(a_),
                 MathTex(r'B^\prime').next_to(b_,DOWN),
                 MathTex(r'C^\prime').next_to(c_,DOWN),
                 MathTex(r'S^\prime').next_to(s_,UP)
                 )

class p2(ThreeDScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        # self.set_camera_orientation(phi=75 * DEGREES, theta=-90 * DEGREES)
        # 1
        a,b=[-2.6,0,0],[-0.5,0,0]
        c,d=b+DL,a+DL
        s=a+UP*1.3+RIGHT*0.5
        vg1=VGroup(
            Line(s,d),Line(s,c),Line(s,b),
            Line(b,c),Line(c,d),
            DashedLine(s,a),
            DashedLine(a,b),DashedLine(a,d)
        ).set_color(LV)
        self.add(vg1,
                 MathTex('A').next_to(a,DOWN),
                 MathTex('B').next_to(b),
                 MathTex('C').next_to(c,DOWN),
                 MathTex('D').next_to(d,DOWN),
                 MathTex('S').next_to(s,UP)
                 )
        # 2
        a_,b_,c_,s_=[3.6,-0.5,0],[2,0,0],[1,-1,0],[2.2,1.5,0]
        vg2=VGroup(
            DashedLine(a_,b_),DashedLine(b_,c_),Line(a_,c_),
            Line(s_,a_),DashedLine(s_,b_),Line(s_,c_)
        ).set_color(JH)
        self.add(vg2,
                 MathTex(r'A^\prime').next_to(a_),
                 MathTex(r'B^\prime').next_to(b_,DOWN),
                 MathTex(r'C^\prime').next_to(c_,DOWN),
                 MathTex(r'S^\prime').next_to(s_,UP)
                 )
        # p2
        m=(s+b)/2
        self.add(DashedLine(a,m),Line(c,m),
                 MathTex('M').next_to(m,UR)
                 )
        n=(np.array(s_)+np.array(b_))/2
        self.add(DashedLine(a_,n),DashedLine(c_,n),
                 MathTex('N').next_to(n,UR)
                 )

class p3(ThreeDScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        # self.set_camera_orientation(phi=75 * DEGREES, theta=-90 * DEGREES)
        # 1
        a,b=[-2.6,0,0],[-0.5,0,0]
        c,d=b+DL,a+DL
        s=a+UP*1.3+RIGHT*0.5
        vg1=VGroup(
            Line(s,d),Line(s,c),DashedLine(s,b),
            Line(b,c),Line(c,d),
            DashedLine(s,a),
            DashedLine(a,b),DashedLine(a,d)
        ).set_color(LV)
        self.add(vg1,
                 MathTex('A').next_to(a,DOWN),
                 MathTex(r'B(B^\prime)').next_to(b),
                 MathTex(r'C(C^\prime)').next_to(c,DOWN),
                 MathTex('D').next_to(d,DOWN),
                 MathTex(r'S(S^\prime)').next_to(s,UP)
                 )
        # p3
        a_=s+RIGHT*2.1
        self.add(
            VGroup(Line(a_,s),Line(a_,b),Line(a_,c)).set_color(JH),
            MathTex(r'A^\prime').next_to(a_),
        )